home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 6.3 KB | 249 lines | [TEXT/ttxt] |
- --<<<-
-
- module QuitQueryExample
- uses ScriptX
- exports SafeTitleContainer, InterfaceButton
- end
- in module QuitQueryExample
-
- class InterfaceButton (PushButton)
- class variables
- buttonBoundary:(new Rect x2:60 y2:20)
- instance variables
- text
- instance methods
- method init self #rest args #key \
- buttonText: -> (
- if isAKindOf buttonText String then (
- self.text := buttonText
- ) else (
- report badParameter #(buttonText, init,
- self, "not a string")
- )
- apply nextMethod self \
- releasedPresenter:(new TextPresenter \
- boundary:InterfaceButton.buttonBoundary \
- target:(self.text) \
- stroke:blackBrush) \
- pressedPresenter:(new TwoDShape \
- target:InterfaceButton.buttonBoundary \
- fill:blackBrush) \
- args
- )
- method afterInit self #rest args #key \
- action: -> (
- setDefaultAttr self.releasedPresenter @alignment @center
- if isAKindOf action AbstractFunction then (
- self.activateAction := action
- ) else (
- report badParameter #(action, afterInit,
- self, "not a function")
- )
- )
- end
-
- class YesNoWindow (Window)
- instance variables
- actuatorController
- textQuery
- textQueryPresenter
- yesButton
- noButton
- theResult:false
- theLock:(new Lock)
- startPipe:(new PipeClass size:1)
- finishPipe:(new PipeClass size:1)
- end
-
- method init self {class YesNoWindow} #rest args -> (
- apply nextMethod self type:@notice args
- )
-
- method afterInit self {class YesNoWindow} #rest args \
- #key question: xPosition: yPosition: -> (
- apply nextMethod self args
- self.actuatorController := new ActuatorController \
- space:self \
- wholeSpace:true
- if isAKindOf question String then
- self.textQuery := question
- else
- report badParameter #(question, afterInit,
- self, "not a string")
- self.textQueryPresenter := new TextPresenter \
- boundary:(new Rect x2:320 y2:20) \
- target:(self.textQuery)
- self.yesButton := new InterfaceButton \
- buttonText:"Yes" \
- action:(a b -> (
- if a.title != theScratchTitle then (
- a.theResult := true
- ) else (
- a.theResult := false
- )); hide a;
- write a.finishPipe a.theResult)
- self.yesButton.authorData := self
- self.noButton := new InterfaceButton \
- buttonText:"No" \
- action:(a b ->
- a.theResult := false
- hide a;
- write a.finishPipe a.theResult)
- self.noButton.authorData := self
-
- -- center the text, so it looks good
- setDefaultAttr self.textQueryPresenter @alignment @center
-
- -- position the three presenters, based on window's dimensions
- local buttonHeight := (self.height * 0.75) as ImmediateInteger
- local buttonCenter := (self.width * 0.50) as ImmediateInteger
- self.yesButton.y := buttonHeight
- self.noButton.y := buttonHeight
- self.yesButton.x := buttonCenter + 10
- self.noButton.x := (buttonCenter - self.noButton.width) - 10
- self.textQueryPresenter.x := buttonCenter - (self.textQueryPresenter.width / 2)
- self.textQueryPresenter.y := (self.height * 0.30) as ImmediateInteger
-
- -- position self
- self.x := xPosition
- self.y := yPosition
-
- -- add the three presenters
- append self self.yesButton
- append self self.noButton
- append self self.textQueryPresenter
- )
-
- method askForYesOrNo self {class YesNoWindow} -> (
- acquire self.theLock
- write self.startPipe true -- unblocks calling thread
- show self
- local myResult := read self.finishPipe -- block
- relinquish self.theLock -- unblocks calling thread
- return myResult
- )
-
- class SafeTitleContainer (TitleContainer)
- instance variables
- transient _quitQueryID
- instance methods
- method quitQueryIDGetter self ->
- self._quitQueryID
- method quitQueryIDSetter self value ->
- if getClass value == ImmediateInteger then
- self._quitQueryID := value
- else
- report badParameter #(value, quitQueryIDSetter,
- self, "not an immediate integer")
- method okayToCloseTitle self -> (
- bringToFront self
- local buildText := "Is it OK to quit the title " +
- self.name + "?"
- local a := new YesNoWindow \
- boundary:(new Rect x2:400 y2:100) \
- question:buildText \
- title:self \
- xPosition:50 \
- yPosition:50
- local modalProcess := new Thread \
- func:askForYesOrNo \
- arg:a
- read a.startPipe
- acquire a.theLock
- print "I was here five"
- local b := modalProcess.result
- return b
- )
- method close self #rest args -> (
- if okayToCloseTitle self then (
- deinstallQuitQuery self.quitQueryID
- apply nextMethod self args
- )
- )
- method startupActionGetter self -> (
- -- make sure only a single quit query is installed
- if self.quitQueryID = undefined do
- self.quitQueryID :=
- installQuitQuery okayToCloseTitle self
- nextMethod self
- )
- end
-
- module QuitQueryTest1
- uses ScriptX
- uses QuitQueryExample
- end
- in module QuitQueryTest1
-
- object mySafeTitle (SafeTitleContainer)
- dir:theStartDir
- path:"quitqone.sxt"
- name:"Wade's Follies"
- end
-
- open TitleContainer path:"quitqone.sxt"
- object myWindow (Window)
- title:mySafeTitle
- name:mySafeTitle.name
- end
- object buttonController (ActuatorController)
- space:myWindow, wholeSpace:true, enabled:true
- end
- object myCloseButton (InterfaceButton)
- buttonText:"Close"
- action:(a b -> new Thread \
- func:(c -> close c) arg:a)
- settings
- x:420, y:360
- end
- myCloseButton.authorData := myWindow.title
- object myQuitButton (InterfaceButton)
- buttonText:"Quit"
- action:(a b -> new Thread func:(c -> quit()))
- settings
- x:500, y:360
- end
- myQuitButton.authorData := myWindow.title
- append myWindow myCloseButton
- append myWindow myQuitButton
- add mySafeTitle 1 myWindow
- show myWindow
-
- module QuitQueryTest2 uses ScriptX, QuitQueryExample end
- in module QuitQueryTest2
-
- object mySafeTitle (SafeTitleContainer)
- dir:theStartDir
- path:"quitqtwo.sxt"
- name:"Ross's Peccadillos"
- end
- open TitleContainer path:"quitqtwo.sxt"
- object myWindow (Window)
- title:mySafeTitle
- name:mySafeTitle.name
- end
- object buttonController (ActuatorController)
- space:myWindow, wholeSpace:true, enabled:true
- end
- object myCloseButton (InterfaceButton)
- buttonText:"Close"
- action:(a b -> new Thread \
- func:(c -> close c) arg:a)
- settings
- x:420, y:360
- end
- myCloseButton.authorData := myWindow.title
- object myQuitButton (InterfaceButton)
- buttonText:"Quit"
- action:(a b -> new Thread func:(c -> quit()))
- settings
- x:500, y:360
- end
- myQuitButton.authorData := myWindow.title
- append myWindow myCloseButton
- append myWindow myQuitButton
- add mySafeTitle 1 myWindow
- show myWindow
-
- -->>>
-